﻿using System.Data;
using ErrorPageZ.Providers;
using Microsoft.ApplicationBlocks.Data;
using visinia.SmartEngine.Providers;

namespace ErrorPageZ
{
    public class SqlDataProvider : ErrorPageZDataProvider
    {
        #region INIT
        private static string _sqlConnectionString = null;

        public SqlDataProvider()
        {
            _sqlConnectionString = ProviderController.GetDataProviderConnectionString();
        }
        public string ConnectionString
        {
            get { return _sqlConnectionString; }
        }
        #endregion

        #region ErrorPageZ
        public override IDataReader GetCustomErrorPages()
        {
            return SqlHelper.ExecuteReader(ConnectionString, "ErrorPageZGetCustomErrorPages");
        }
        public override void SetCustomErrorPage(int statusCode, string redirect, int PageId)
        {
            SqlHelper.ExecuteNonQuery(ConnectionString, "ErrorPageZSetCustomErrorPage", statusCode, redirect, PageId);
        }

        public override void ResetCustomErrorPage(int statusCode)
        {
            SqlHelper.ExecuteNonQuery(ConnectionString, "ErrorPageZResetCustomErrorPage", statusCode);
        }
        #endregion
    }
}
